//封装一个运动框架
var getCss = function(obj, attr) {
	if(obj.currentStyle) {
		return obj.currentStyle[attr]
	} else {
		return getComputedStyle(obj, false)[attr]
	}
}

var animates = function(obj, json, fn) {
	//把定时器挂在到当前对象的一个timer属性上
	clearInterval(obj.timer);
	obj.timer = setInterval(function() {
		var bDone = true;
		for(var attr in json) {
			//遍历json里面的属性
			var icur = 0;
			if(attr === "opacity") {
				icur = parseInt(parseFloat(getCss(obj, attr) * 100));
			} else {
				icur = parseInt(getCss(obj, attr));
			}
			//速度=（目标点（就是我们json传过来的位置）-当前点）/3
			var speed = (json[attr] - icur) / 3;
			//判断当前速度的正负，并把跟新的值赋给自身
			//ceil()是对数进行向上取整，floor()是向下取整
			speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
			if(icur != json[attr]) {
				bDone = false;
			}
			//透明度额外处理
			if(attr === "opacity") {
				obj.style[attr] = (icur + speed) / 100;
				obj.style.filter = "alpha(opacity="+(icur+speed)+")";
			} else {
				obj.style[attr] = parseInt(icur) + speed + "px";
			}
		}
		if(bDone) {
			clearInterval(obj.timer);
			if(fn && typeof fn === "function") {
				//为了容错
				fn();
			}
		}
	}, 60)
};
var par = document.getElementById("par");
var partner = document.getElementById("partner");
var aUl = partner.children;
var ali1 = aUl[0].children;
var ali2 = aUl[1].children;
var ali3 = aUl[2].children;
var ali = partner.getElementsByTagName("li")
par.onmouseenter = function() {
	for(var i = 0; i < 10; i++) {
		var li1 = ali[i]
		if(i < 3) {
			animates(li1, { "top": "125", "opacity": "100" })
		} else if(i > 2 && i < 7) {
			animates(li1, { "opacity": "100" })
		} else {
			animates(li1, { "top": "500", "opacity": "100" })
		}
	}
};

//ie兼容8以下
function getClassNames(classStr,tagName){
      if (document.getElementsByClassName) {
            return document.getElementsByClassName(classStr)
      }else {
            var nodes = document.getElementsByTagName(tagName),ret = [];         
            for(i = 0; i < nodes.length; i++) {
         if(hasClass(nodes[i],classStr)){
                ret.push(nodes[i])
         }
      }
      return ret;
       }
}
function hasClass(tagStr,classStr){
     var arr=tagStr.className.split(/\s+/ );  //这个正则表达式是因为class可以有多个,判断是否包含
     for (var i=0;i<arr.length;i++){
            if (arr[i]==classStr){
                  return true ;
            }
     }
     return false ;
};

			var line = $("#line");
			var nav_li = $(".nav a");
			var nav_w = nav_li.first().width() + 20 + "px";
			line.width(nav_w);
			line.css({ left: 20 });
			nav_li.on('click', function() {
				nav_w = $(this).width() + 10 + "px";
				line.width(nav_w);
				line.animate({ left: $(this).position().left + 20 }, 300);
				$(this).addClass("act").siblings().removeClass("act");
				var index = $(this).index();
				if(index == 0) {
					
					$(".pages").eq(0).addClass("show").siblings().removeClass("show");
				} else if(index == 1) {
					
					$(".pages").eq(1).addClass("show").siblings().removeClass("show");
				} else if(index == 2){
					$(".pages").eq(2).addClass("show").siblings().removeClass("show");
					getMap();
				}else if(index == 3){
					//console.log(3333);
					$(".pages").eq(3).addClass("show").siblings().removeClass("show");
				}
			});

			//info显示效果
			window.onscroll = function() {
				var wtop = document.documentElement.scrollTop || document.body.scrollTop;
				var inter_ul = document.getElementById("inter_ul");
				var inter_lis = inter_ul.getElementsByTagName("div");
				var info = document.getElementById("info");
				var f = info.getBoundingClientRect().top;
				if(f < 820) {
					var infos = getClassNames('info_s', 'div');

					var len = infos.length;
					for(var i = 0; i < len; i++) {
						var li = infos[i];
						(function(i) {
							setTimeout(function() {
								animates(infos[i], { "opacity": "100" })
							}, 300 * i)
						})(i)
					}
				}
				var property = document.getElementById("property");
				var property_top = document.getElementById("property_top");
				var property_center = document.getElementById("property_center");
				var property_foot = document.getElementById("property_foot");
				var p = property.getBoundingClientRect().top;
				if(p < 800) {
					animates(property_top, { "opacity": "100", "left": "0" });
					animates(property_center, { "opacity": "100", "top": "0" });
					animates(property_foot, { "opacity": "100", "left": "0" });
				}
				if(wtop > 1400 && wtop < 2600) {
					for(var i = 0; i < 3; i++) {
						var li = inter_lis[i];
						(function(i) {
							setTimeout(function() {
								animates(inter_lis[i], { "opacity": "100" })
							}, 600 * i)
						})(i)
					}
				}
				if(wtop > 2100 && wtop < 3800) {
					var oUl = document.getElementById("yun_ul");
					var lis = oUl.getElementsByTagName("li");
					for(var i = 0; i < lis.length; i++) {
						var li = lis[i];
						if(i % 2 == 0) {
							animates(li, { "top": "62", "opacity": "100" });
						} else {
							animates(li, { "top": "-2", "opacity": "100" });
						}
					}
				}
			};

			function getMap() {
				// 百度地图API功能
				var map = new BMap.Map("allmap");
				var point = new BMap.Point(120.064339, 30.290748);
				map.centerAndZoom(point, 14);
				var marker = new BMap.Marker(point); // 创建标注
				map.addOverlay(marker); // 将标注添加到地图中
				marker.addEventListener("click", getAttr);
				map.enableScrollWheelZoom(true);

				function getAttr() {
					var p = marker.getPosition(); //获取marker的位置
				}
			};
			